{extend name='public/list'/}
<!-- 头部 -->
{block name='head'}
<div class="layui-tab layui-tab-brief">
    <ul class="layui-tab-title">
        <li><a href="/admins/setting/index" title="设置列表">设置列表</a></li>
        <li class="layui-this"><a href="/admins/config/index" title="配置选项">配置选项</a></li>
    </ul>
</div>
<div class="layui-tab-content">
    {/block}
    <!-- 表单字段 -->
    {block name='fields'}
    <div class="layui-inline">
        <label class="layui-form-label">字段名</label>
        <div class="layui-input-block">
            <select name="sid">
                <option value=""></option>
                {foreach $setting as $key => $vo}
                <option value="{$key}">{$vo}</option>
                {/foreach}
            </select>
        </div>
    </div>
    <!-- <div class="layui-inline">
        <label class="layui-form-label">标签或名称</label>
        <div class="layui-input-block">
            <input type="text" name="label|name" value="" placeholder="标签或名称" class="layui-input">
        </div>
    </div> -->
    {/block}
    {block name='submit'}
    <div class="layui-inline">
        <button type="submit" lay-submit lay-filter="search" class="layui-btn">筛选</button>
    </div>
    {/block}
    <!-- 底部 -->
    {block name='bottom'}
</div>
{/block}
<!-- js -->
{block name='js'}
<script>
    var cols = [
        [{
            checkbox: true,
            fixed: 'left',
        }, {
            field: 'id',
            title: 'ID',
            sort: true,
            width: 80,
        }, {
            field: 'stitle',
            title: '字段名',
            sort: true,
        }, {
            field: 'label',
            title: '标签名',
            sort: true,
        }, {
            field: 'type',
            title: '类型',
            sort: true,
        }, {
            field: 'name',
            title: '名称',
        }, {
            field: 'value',
            title: '默认值',
            edit: 'text',
        }, {
            field: 'ord',
            title: '排序',
            edit: 'text',
            sort: true,
        }, {
            field: 'status',
            title: '状态',
            sort: true,
            width: 95,
            templet: function (res) {
                return '<input type="checkbox" name="status" lay-filter="status" value="' + res.id + '" lay-skin="switch" lay-text="启用|禁用"' + (res.status == 0 ? ' checked' : '') + '>';
            }
        }, {
            field: 'time',
            title: '时间',
            sort: true,
        }, {
            title: '操作',
            align: 'center',
            width: 120,
            toolbar: '#databar'
        }]
    ];

    // 列表开关事件
    layui.use(['form', 'table'], function () {
        var form = layui.form
            , table = layui.table
            , $ = layui.jquery;
        form.on('switch(status)', function (obj) {
            $.post('/admins/config/save_edit', { id: this.value, status: obj.elem.checked ? 0 : 1 }, function (res) {
                if (res.code) {
                    layer.alert(res.msg, { icon: 2 });
                    setTimeout(function () {
                        table.reload('dataTable');
                        layer.close();
                    }, 1000);
                    return;
                }
                layer.msg(res.msg);
            }, 'json');
        });
        return false;
    });
</script>
{/block}